﻿Partial Public Class Main

    Private Sub SQLMemoryManager()
        GrantedWorkspaceMemory()
        MaximumWorkspaceMemory()
        MemoryGrantsOutstanding()
        MemoryGrantsPending()
        TargetServerMemory()
        TotalServerMemory()
    End Sub

    Private Sub GrantedWorkspaceMemory()
        CalculateCounter("Granted Workspace Memory (KB)",
                          CStr(IIf(instanceName = "Default", "SQLServer:Memory Manager", "MSSQL$" + instanceName + ":Memory Manager")),
                          Me.txtGWMmin,
                          Me.txtGWMmax,
                          Me.txtGWMavg,
                          Me.sparklineGrantedWorkspaceMemory)

    End Sub

    Private Sub MaximumWorkspaceMemory()
        CalculateCounter("Maximum Workspace Memory (KB)",
                              CStr(IIf(instanceName = "Default", "SQLServer:Memory Manager", "MSSQL$" + instanceName + ":Memory Manager")),
                              Me.txtMWMmin,
                              Me.txtMWMmax,
                              Me.txtMWMavg,
                              Me.sparklineMaximumWorkspaceMemory)

    End Sub

    Private Sub MemoryGrantsOutstanding()
        CalculateCounter("Memory Grants Outstanding",
                              CStr(IIf(instanceName = "Default", "SQLServer:Memory Manager", "MSSQL$" + instanceName + ":Memory Manager")),
                              Me.txtMGOmin,
                              Me.txtMGOmax,
                              Me.txtMGOavg,
                              Me.sparklineMemoryGrantsOutstanding)

    End Sub

    Private Sub MemoryGrantsPending()
        CalculateCounter("Memory Grants Pending",
                              CStr(IIf(instanceName = "Default", "SQLServer:Memory Manager", "MSSQL$" + instanceName + ":Memory Manager")),
                              Me.txtMGPmin,
                              Me.txtMGPmax,
                              Me.txtMGPavg,
                              Me.sparklineMemoryGrantsPending)
    End Sub

    Private Sub TargetServerMemory()
        CalculateCounter("Target Server Memory (KB)",
                                  CStr(IIf(instanceName = "Default", "SQLServer:Memory Manager", "MSSQL$" + instanceName + ":Memory Manager")),
                                  Me.txtTSMmin,
                                  Me.txtTSMmax,
                                  Me.txtTSMavg,
                                  Me.sparklineTargetServerMemory)

    End Sub

    Private Sub TotalServerMemory()
        CalculateCounter("Total Server Memory (KB)",
                          CStr(IIf(instanceName = "Default", "SQLServer:Memory Manager", "MSSQL$" + instanceName + ":Memory Manager")),
                          Me.txtTotalSMmin,
                          Me.txtTotalSMmax,
                          Me.txtTotalSMavg,
                          Me.sparklineTotalServerMemory)
    End Sub
End Class
